package com.zlzxm.shoesmarket.view.adapter;

import android.text.Html;
import android.text.TextUtils;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.zlzxm.shoesmarket.R;
import com.zlzxm.shoesmarket.util.ZViewHelp;
import com.zlzxm.shoesmarket.view.adapter.entity.EntityRepositoryGoods;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
 * CREATE BY zlzxm ON 4/8/21
 */
public class ADRepositoryGoods extends BaseQuickAdapter<EntityRepositoryGoods, BaseViewHolder> {

    public ADRepositoryGoods( @Nullable List<EntityRepositoryGoods> data) {
        super(R.layout.item_repository_goods, data);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, EntityRepositoryGoods goods) {

        holder.setText(R.id.tvNum,goods.getNum());

        holder.setText(R.id.tvCost,goods.getCost());

        holder.setText(R.id.tvTitle,goods.getTitle());

        holder.setText(R.id.tvDesc,goods.getDesc());


        RoundedCorners roundedCorners = new RoundedCorners(ZViewHelp.dpTopx(getContext(),4));

        RequestOptions requestOptions = new RequestOptions().transform(new CenterCrop(),roundedCorners);

        Glide.with(getContext())
                .load(goods.getFace())
                .apply(requestOptions)
                .into((ImageView) holder.getView(R.id.ivFace));


        if(!TextUtils.isEmpty(goods.getProfit())) {

            if (goods.getProfit().contains("+")) {

                holder.setText(R.id.tvProfit, Html.fromHtml("<font color=\"#CF4626\">" + goods.getProfit() + "</font>"));

            } else if (goods.getProfit().contains("-")) {

                holder.setText(R.id.tvProfit, Html.fromHtml("<font color=\"#5B8C00\">" + goods.getProfit() + "</font>"));
            }else {
                holder.setText(R.id.tvProfit,goods.getProfit());
            }

        }else {
            holder.setText(R.id.tvProfit,null);
        }

        if(!TextUtils.isEmpty(goods.getRealProfit())) {

            if (goods.getRealProfit().contains("+")) {

                holder.setText(R.id.tvRealProfit, Html.fromHtml("<font color=\"#CF4626\">" + goods.getProfit() + "</font>"));

            } else if (goods.getProfit().contains("-")) {

                holder.setText(R.id.tvRealProfit, Html.fromHtml("<font color=\"#5B8C00\">" + goods.getProfit() + "</font>"));
            }else {
                holder.setText(R.id.tvRealProfit, goods.getRealProfit());
            }


        }else {
            holder.setText(R.id.tvRealProfit, null);
        }
    }

}
